<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="attachmentList.title"/></title>
    <meta name="menu" content="AttachmentListMenu"/>
</head>

<script type="text/javascript">var batchexportMessage ="<fmt:message key="sendAttachment.batch.message"/>";</script>
<script type="text/javascript">var shipNumberMessage ="<fmt:message key="sendAttachment.shipNumber.message"/>";</script>

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        <fmt:message key="materialList.heading"/>
        <small><p><fmt:message key="materialList.message"/></p></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i><fmt:message key="materialList.heading"/></a></li>
        <li class="active"> <fmt:message key="materialList.heading"/></li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <%@ include file="/common/messages.jsp" %>
            <div class="box">
                <div class="box-header">
                    <h3 class="box-title"> <fmt:message key="materialList.heading"/></h3>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <form action="sendMaterialsForm" method="get">
                        <input type="hidden" name="maId" value="${param.maId}"/>
                    <display:table name="materialAudit.materialList" class="table table-condensed table-striped table-hover" requestURI="" id="materialList" export="false" pagesize="100">
                        <display:column titleKey="button.select" sortable="false" style="width: 3%;">
                            <c:choose>
                                <c:when test="${not materialList.sent and not materialList.received }">
                                    <input type="checkbox" name="selectedMaterials" value="<c:out value="${materialList.name}"/>"/>
                                </c:when>
                                <c:when test="${not materialList.sent and materialList.received }">
                                    <input type="checkbox" name="selectedMaterials" value="<c:out value="${materialList.name}"/>" disabled checked="checked"/>
                                </c:when>
                                <c:when test="${materialList.sent and not materialList.received }">
                                    <input type="checkbox" name="selectedMaterials" value="<c:out value="${materialList.name}"/>" checked="checked"/>
                                </c:when>
                                <c:otherwise>
                                    <input type="checkbox" name="sentIds" value="<c:out value="${materialList.name}"/>" disabled checked="checked"/>
                                </c:otherwise>
                            </c:choose>
                        </display:column>
                        <display:column property="id" media="csv excel xml pdf" titleKey="attachment.id"/>
                        <display:column sortable="true" titleKey="attachment.name" style="width: 40%;"><fmt:message key="MATERIAL_${materialList.name}"/></display:column>
                        <display:column titleKey="material.loanRequested" sortable="false" style="width: 20%;">
                            <c:choose>
                                <c:when test="${not materialList.loanRequest}">
                                    <input type="checkbox" name="loanRequestedMaterials" value="<c:out value="${materialList.name}"/>" disabled/>
                                </c:when>
                                <c:otherwise>
                                    <input type="checkbox" name="loanRequestedMaterials" value="<c:out value="${materialList.name}"/>" disabled checked="checked"/>
                                </c:otherwise>
                            </c:choose>
                        </display:column>
                        <display:column property="shipNumber" sortable="true" titleKey="material.shipNumber" style="width: 20%;"></display:column>
                        <display:column titleKey="button.received" sortable="false" style="width: 3%;">
                            <c:choose>
                                <c:when test="${not materialList.received}">
                                    <input type="checkbox" name="receivedMaterials" value="<c:out value="${materialList.name}"/>" disabled/>
                                </c:when>
                                <c:otherwise>
                                    <input type="checkbox" name="receivedIds" value="<c:out value="${materialList.name}"/>" disabled checked="checked"/>
                                </c:otherwise>
                            </c:choose>
                        </display:column>
                    </display:table>
                        <div>
                        <label><fmt:message key="material.shipNumber"/>: </label>
                        <input name="shipNumber" type="text" size="20"/>
                        </div>
                        <button type="submit" class="btn btn-primary" id="batchAudit" name="batchAudit" onclick="return checkBatch();">
                            <i class="icon-ok icon-white"></i> <fmt:message key="button.material.send"/>
                        </button>
                        <a class="btn btn-primary margin" href='/loanRequestform?reqId=${materialAudit.loanRequest.id}'><fmt:message key="button.back"></fmt:message></a>
                    </form>
                </div><!-- /.box -->
            </div>
    </div>



</section><!-- /.content -->

<c:set var="scripts" scope="request">
    <script type='text/javascript' src="<c:url value='/dwr/interface/UserManager.js'/>"></script>
    <script type='text/javascript' src="<c:url value='/dwr/engine.js'/>"></script>
    <script type='text/javascript' src="<c:url value='/dwr/util.js'/>"></script>
<script type="text/javascript">
    $(function () {


    });

    function checkBatch() {
        var selectedIds = $("input[name='selectedMaterials']:checked").val();
        var shipNumber = $("input[name='shipNumber']").val();
        if (!selectedIds || selectedIds.length == 0) {
            alert(batchexportMessage);
            return false;
        } else if (shipNumber == "") {
            alert(shipNumberMessage);
            return false;
        } else {
            return true;
        }
    }

</script>
</c:set>
